package com.serverapk.util;

import android.content.Context;
import android.view.Gravity;

/**
 * Created by dalu on 2016/1/16 13:19.
 *
 * @Version 2.0
 * @Desc ToastUtil
 */
public class ToastUtil {

    private static android.widget.Toast toast;

    /**
     * 短时间显示Toast(默认)
     *
     * @param context
     * @param message
     */
    public static void showShort(Context context, CharSequence message) {
        if (null == toast && context != null) {
            toast = android.widget.Toast.makeText(context, message,
                    android.widget.Toast.LENGTH_SHORT);
        } else {
            if (context != null)
                toast.setText(message);
        }
        toast.show();
    }

    /**
     * 短时间显示Toast(默认)
     *
     * @param context
     * @param message
     */
    public static void showShort(Context context, CharSequence message, int type) {
        if (null == toast && context != null) {
            toast = android.widget.Toast.makeText(context, message,
                    android.widget.Toast.LENGTH_SHORT);
        } else {
            if (context != null) {
                toast.setText(message);
            }
        }
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    /**
     * 长时间显示Toast(默认)
     *
     * @param context
     * @param message
     */
    public static void showLong(Context context, CharSequence message) {
        if (null == toast) {
            toast = android.widget.Toast.makeText(context, message,
                    android.widget.Toast.LENGTH_LONG);
        } else {
            toast.setText(message);
        }
        toast.show();
    }
}
